<?php
/*************************************************************************
Avasoft CMS Project
Company: Avasoft Co., Ltd                                  
Name: Tran Thi Kim Que
Last updated: 08/03/2011
**************************************************************************/

//error_reporting  (E_ERROR | E_WARNING | E_PARSE) ;
//ini_set('display_errors','1'); ini_set('display_startup_errors','1'); 
include_once(ROOT_PATH."includes/functions.php");
include_once(ROOT_PATH."classes/dao/members.class.php");
include_once(ROOT_PATH."classes/dao/phpmailer.class.php");
include_once(ROOT_PATH."classes/dao/smtp.class.php");
$members = new Members();
$templateFile = "forgot.tpl.html";
$email = $request->element('email','');
$username = $request->element('username','');
$pageName = "Quên mật khẩu";
$template->assign('pageName',$pageName);
if($_POST){
		$result= $members->checkDuplicate($email,"email");
		$result1= $members->checkDuplicate($username,"username");
		if($result==1 && $result1==1){
		$userItem= $members->getRecordFromEmail($email);
		$userId = $userItem->getId();
		$new_pass=rand();
		$passmd5= md5($new_pass);
		$fields =array('password'=>$passmd5);
		$members->updateData($fields,$userId,'id');
		$comment=$messages["forgot_pass"];
		$admin_mail = "kque.tran@gmail.com";
			$ip = $_SERVER["REMOTE_ADDR"];
			$user_agent = $_SERVER['HTTP_USER_AGENT'];
			$response="\n$comment\nPassword: $new_pass\n";
			//mail("info@mypapit.net","Contact form fakapster",$response, $headers);
			$mail = new PHPmailer();
			$mail->From = $email;
			$mail->FromName = DOMAIN;
			$mail->Host = SMTP_HOST;
			$mail->Mailer   = "smtp";
			$mail->Password = SMTP_PASSWORD;
			$mail->Username =SMTP_USER;
			$mail->Subject = "Thông tin mật khẩu";
			$mail->SMTPAuth  =  "true";
			$mail->Body = $response;
			//$email="kimque@ava.vn";
			$mail->AddAddress($email,$email);
			//$mail->AddReplyTo($email,$email);
			$mail->Send(); 	
			$mail->ClearAddresses();
			$mail->ClearAttachments();	
			$error = $messages["forgot_ok"];
				$template->assign("error",$error);
		}
}



#supprot
 include_once(ROOT_PATH."classes/dao/procategories.class.php");
$productcategories = new ProductCategories();
$productcatItems = $productcategories->getObjects(1,"status =1 AND pid=0",array('position'=>'ASC'),'');
$template->assign('productcatItems',$productcatItems);
$template->assign('productcategories',$productcategories);
 #end support
 #supprot
 include_once(ROOT_PATH."classes/dao/parts.class.php");
$parts = new Parts();
$partItems = $parts->getObjects(1,"status =1",array('id'=>'ASC'),1);
$template->assign('partItems',$partItems);
$template->assign('parts',$parts);
 #end support
 #chuyen muc
 include_once(ROOT_PATH."classes/dao/categories.class.php");
$categories = new Categories();
$categoryItems = $categories->getObjects(1,"status =1 AND pid=0",array('position'=>'ASC'),'');
$template->assign('categoryItems',$categoryItems);
$template->assign('categories',$categories);
 #chuyen muc
  #tim tuc left
 include_once(ROOT_PATH."classes/dao/entries.class.php");
$entries = new Entries();
$leftEntriesItems = $entries->getObjects(1,"status =1 AND cid=1",array('date_created'=>'DESC'),3);
$template->assign('leftEntriesItems',$leftEntriesItems);
$template->assign('entries',$entries);
 #end tin tuc left

?>